Shader "Custom/GridShader"
{
    Properties
    {
        _LineColor ("Line Color", Color) = (1, 1, 1, 1)
        _GridSize ("Grid Size", Range(1, 100)) = 10
    }

    SubShader
    {
        Tags { "RenderType"="Opaque" }

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
            };

            struct v2f
            {
                float4 vertex : SV_POSITION;
            };

            float _GridSize;
            fixed4 _LineColor;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float2 uv = i.vertex.xy;
                float2 gridUV = floor(uv * _GridSize) / _GridSize;
                float borderSize = 0.01;
                float2 borderMask = smoothstep(-borderSize, 0.0, fwidth(uv));

                fixed4 color = _LineColor;
                color.rgb *= borderMask.x * borderMask.y; // Apply border mask

                return color;
            }
            ENDCG
        }
    }
}